package com.smmisia.article.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smmisia.article.dto.accompany.AccompanyCreateDTO;
import com.smmisia.article.dto.accompany.AccompanyUpdateDTO;
import com.smmisia.article.entity.Accompany;
import com.smmisia.article.response.accompany.AccompanyAuditResponse;
import com.smmisia.article.response.accompany.AccompanyResponse;
import com.smmisia.article.service.AccompanyService;
import com.smmisia.common.Result.Result;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;

@RestController
@RequestMapping
@Tag(name = "结伴接口")
public class AccompanyController {

    @Autowired
    private AccompanyService accompanyService;

    @PostMapping("/insert")
    @Operation(summary = "创建结伴")
    public Result<Long> createAccompany(@RequestBody @Valid AccompanyCreateDTO dto) {
        return accompanyService.createAccompany(dto);
    }

    @PostMapping("/join/{id}")
    @Operation(summary = "申请加入结伴")
    public Result<Void> joinAccompany(@PathVariable("id") Long accompanyId) {

        return accompanyService.joinAccompany(accompanyId);
    }

    @PostMapping("/audit/{id}")
    @Operation(summary = "审核结伴申请")
    public Result<Void> auditAccompanyApply(
            @PathVariable("id") Long memberId,
            @RequestParam Boolean approved) {

        return accompanyService.auditAccompanyApply(memberId, approved);
    }

    @GetMapping("/page")
    @Operation(summary = "分页查询结伴列表")
    public Result<Page<Accompany>> queryAccompanyPage(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer size) {
        return accompanyService.queryAccompanyPage(page, size);
    }

    @GetMapping("/my-joined")
    @Operation(summary = "查询我参加的结伴")
    public Result<Page<Accompany>> queryMyJoinedAccompany(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer size) {
        return accompanyService.queryMyJoinedAccompany(page, size);
    }

    @GetMapping("/my-created")
    @Operation(summary = "查询我发布的结伴")
    public Result<Page<Accompany>> queryMyCreatedAccompany(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer size) {
        return accompanyService.queryMyCreatedAccompany(page, size);
    }

    @PutMapping("/{id}")
    @Operation(summary = "更新结伴信息")
    public Result updateAccompany(
            @PathVariable Long id,
            @RequestBody @Valid AccompanyUpdateDTO dto) {
        return accompanyService.updateAccompany(id, dto);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除结伴")
    public Result deleteAccompany(@PathVariable Long id) {
        return accompanyService.deleteAccompany(id);
    }

    @GetMapping("/getById")
    @Operation(summary = "根据id查询结伴")
    public Result<AccompanyResponse> getAccompanyById(@RequestParam Long id) {
        return accompanyService.getAccompanyById(id);
    }

    @GetMapping("/auditList")
    @Operation(summary = "查询待审核的结伴")
    public Result<List<AccompanyAuditResponse>> queryAccompanyAuditList(@RequestParam Long id){
        return accompanyService.queryAccompanyAuditList(id);
    }
} 